<?php
/**
 * RUBIK IT Solution & Development ltd.
 *
 * PROJECT		: Rubik Ultimate
 * @version 	: 1.1
 * COPYRIGHT	: 2008
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 *
 * @author			hoadn <hoadn@rubik.com.vn>
 * @access			[public/private]
 * @package		 [package name]
 *
 * Created on	:Sep 19, 2008
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

RCoreImporter::cls('html.fieldInfo.BasicHtmlFieldInfo');

class JsCalendarDateHtmlFieldInfo extends BasicHtmlFieldInfo {

	var $_viewFormat 	= 'd/m/Y';
	var $_jsDateFormat = '%Y-%m-%d';
	
	/**
	 * Function for geting the html for inputing data
	 *
	 * @abstract 
	 * @return string
	 */
	function getHtmlInputData($dataType = '', $extAttribute = '') {
		SysResponse::addStyleSheetFile(SYS_ROOT_URL.'ext/jscalendar/calendar-win2k-1.css');
		SysResponse::addJavascriptFile(SYS_ROOT_URL.'ext/jscalendar/calendar.js');
		SysResponse::addJavascriptFile(SYS_ROOT_URL.'ext/jscalendar/lang/calendar-en.js');
		SysResponse::addJavascriptFile(SYS_ROOT_URL.'ext/jscalendar/calendar-setup.js');
		
		$db = SysDatabase::getInstance();
		$format = $db->getFormatDateTime($dataType);
		
		$pickerHtml = '
		<img style="float: left;margin-left: 10px;" src="'.SYS_ROOT_URL.'ext/jscalendar/ew_calendar.gif" border="0" id="px_'.$this->_basicName.'" alt="Pick a Date"  style="cursor:pointer;cursor:hand;display:block;">
			<script type="text/javascript">
			Calendar.setup(
				{
				inputField : "'.$this->_basicName.'", // ID of the input field
				ifFormat : "'.$this->_jsDateFormat.'", // the date format
				button : "px_'.$this->_basicName.'" // ID of the button
				}
			);
			</script>&nbsp;		';
		$extAttribute .= 'style="width: 100px; float: left;"';
		$inputHtml = parent::getHtmlInputData($dataType,$extAttribute);
		$inputHtml .= $pickerHtml;
		return $inputHtml;
	}
	
	function setViewDateFormat($format) {
		$this->_jsDateFormat = $format;
	}
	
	/**
	 * Build the html for previewing the data
	 * NOTE: please override in case special treat
	 * 
	 * @param string $extAttributes
	 * @param int $key key value
	 * @param string $dataType DB Field data type
	 * @return string
	 */
	function buildHtmlPreviewData($extAttributes = '', $key=null, $dataType ='S') {
		$db = SysDatabase::getInstance();
		$ts = $db->convertDbToTimeStamp($this->_value, $dataType);
		return date($this->_viewFormat, $ts);
	}
	
//	/**
//	 * Function for geting the html for previewing data
//	 *
//	 * @return string
//	 */
//	function getPreviewDataHtml($dataType = '', $key = '', $extAttributes = '', $borderTag = 'div') {
//		return $dataType;
//	}
	
	
	/**
	 * For checking if we need to create the filter header
	 * NOTE: please override in case special treat
	 *
	 * @return boolean
	 */
	function shouldCreateFilter() {
		return false;
	}
}
?>